package cn.itcast.listener;

import cn.itcast.domain.system.User;
import cn.itcast.uils.MailUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class EmailListener implements MessageListener {

    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();

        try {

            User user = objectMapper.readValue(body,User.class);

            //发送邮件
            /*
               参数一： 接收人
               参数二： 邮件的主题
               参数三： 邮件的正文内容
             */

            MailUtil.sendMsg(user.getEmail(),"", "您好，您的合同交货期限只剩3天，请尽快交货");

            System.out.println("发送邮件成功！");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
